package com.three.lab.fragment;

import android.content.Context;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.os.Handler;
import android.view.View;
import android.widget.TextView;

import com.three.lab.R;
import com.three.lab.base.AppConstant;
import com.three.lab.base.AppManager;
import com.three.lab.base.BaseFragment;
import com.three.lab.page.address.AddressListActivity;
import com.three.lab.page.common.AboutUsActivity;
import com.three.lab.page.goods.CollectListActivity;
import com.three.lab.page.goods.CouponListActivity;
import com.three.lab.page.goods.FollowListActivity;
import com.three.lab.page.goods.FootPrintActivity;
import com.three.lab.page.message.MessageListActivity;
import com.three.lab.page.message.ServiceMsgActivity;
import com.three.lab.util.XpopupUtil;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link MeFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class MeFragment extends BaseFragment {

    private TextView textView,tvTitle,tvPay,tvSend,tvReceive,tvEvaluate;

    public static MeFragment newInstance(int index, String title) {
        MeFragment fragment = new MeFragment();
        Bundle args = new Bundle();
        args.putInt(AppConstant.INDEX, index);
        args.putString(AppConstant.INDEX_NAME, title);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initArguments(Bundle bundle) {}

    @Override
    protected int bindLayout() {
        return R.layout.fragment_me;
    }

    @Override
    protected void initViews(View view, Bundle savedInstanceState) {
//        tvTitle = $(R.id.tv_title);
//        tvTitle.setText(R.string.me);
//        $(R.id.iv_left).setVisibility(View.GONE);

        tvPay = $(R.id.tv_pay);
        tvSend = $(R.id.tv_send);
        tvReceive = $(R.id.tv_receive);
        tvEvaluate = $(R.id.tv_evaluate);
    }

    @Override
    public void initListener() {
        $(R.id.ll_address).setOnClickListener(this);
        $(R.id.ll_about).setOnClickListener(this);
        $(R.id.btn_exit).setOnClickListener(this);

        $(R.id.ll_all_order).setOnClickListener(this);
        $(R.id.fl_wait_pay).setOnClickListener(this);
        $(R.id.fl_wait_send).setOnClickListener(this);
        $(R.id.fl_wait_receive).setOnClickListener(this);
        $(R.id.fl_wait_evaluate).setOnClickListener(this);
        $(R.id.fl_wait_service).setOnClickListener(this);
        $(R.id.fl_message).setOnClickListener(this);
        $(R.id.iv_service).setOnClickListener(this);
        $(R.id.ll_collet).setOnClickListener(this);
        $(R.id.ll_follow).setOnClickListener(this);
        $(R.id.ll_coupon).setOnClickListener(this);
        $(R.id.ll_footprints).setOnClickListener(this);
    }

    @Override
    public void widgetClick(View v) {
        switch (v.getId()){
            case R.id.ll_about:
                startActivity(AboutUsActivity.class);
                break;
            case R.id.ll_address:
                startActivity(AddressListActivity.class);
                break;
            case R.id.btn_exit:
                onExit();
                break;
            case R.id.ll_all_order:
                jumpOrder(0);
                break;
            case R.id.fl_wait_pay:
                jumpOrder(1);
                break;
            case R.id.fl_wait_send:
                jumpOrder(2);
                break;
            case R.id.fl_wait_receive:
                jumpOrder(3);
                break;
            case R.id.fl_wait_evaluate:
                jumpOrder(4);
                break;
            case R.id.fl_wait_service:
                jumpOrder(5);
                break;
            case R.id.fl_message:
                startActivity(MessageListActivity.class);
                break;
            case R.id.iv_service:
                startActivity(ServiceMsgActivity.class);
                break;
            case R.id.ll_collet:
                startActivity(CollectListActivity.class);
                break;
            case R.id.ll_follow:
                startActivity(FollowListActivity.class);
                break;
            case R.id.ll_coupon:
                startActivity(CouponListActivity.class);
                break;
            case R.id.ll_footprints:
                startActivity(FootPrintActivity.class);
                break;
        }
    }

    private void jumpOrder(int i) {

    }

    private void onExit() {
        XpopupUtil.showOnce(getActivity(), getString(R.string.Are_you_sure_you_want_to_quit), new XpopupUtil.OnPopupOkListener() {
            @Override
            public void onPopupConfirm() {
                exitTing();
            }
        });
    }

    private void exitTing() {
        showLoading(getString(R.string.exitting));
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                hideLoading();
                AppManager.reLogin(getActivity());
            }
        },500);
    }

    @Override
    protected void initData(Context context) {
        tvPay.setText("23");
        tvSend.setText("3");
        tvReceive.setText("5");
        tvEvaluate.setText("2");
    }
}